#ifndef __WEBGLK_H__
#define __WEBGLK_H__

#include "glk.h"
#include <stdio.h>

#ifndef NULL
#define NULL 0
#endif

typedef struct glk_window_struct window_t;
typedef struct glk_stream_struct stream_t;
typedef struct glk_fileref_struct fileref_t;

struct glk_window_struct
{
	char inuse;
	glui32 rock;

	strid_t str;

	winid_t parent;
	winid_t key;
	winid_t child1,child2;

	glui32 x,y;
	glui32 width,height;
	glui32 method,size,type;
};

#define strtype_File (1)
#define strtype_Window (2)
#define strtype_Memory (3)
struct glk_stream_struct
{
	char inuse;
	glui32 rock;
	int type;

	int readable,writable;

	winid_t win;
	glui32 buf;
	glui32 ptr;
	glui32 endbuf;
	glui32 readcount,writecount;

	char unicode;

	frefid_t file;
};
struct glk_fileref_struct
{
	char inuse;
	glui32 rock;

	glui32 fmode;
	glui32 usage;
};

void glk_stream_buffer_open();
void glk_stream_buffer_flush();
void glk_stream_buffer_close();

strid_t glk_stream_new_window(winid_t);

void glk_window_save(FILE *);
void glk_stream_save(FILE *);
void glk_fileref_save(FILE *);

void glk_window_load(FILE *);
void glk_stream_load(FILE *);
void glk_fileref_load(FILE *);

void fatal(const char *fmt,...);

#endif
